const Mock = require("mockjs");
const Random = Mock.Random;
const getQuestionList = require("./data/getQuestionList.js");
module.exports = [
  {
    url: "/api/question/:id",
    method: "get",
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id(),
          title: Random.ctitle(),
          componentList: [
            {
              fe_id: Random.id(),
              type: "questionTitle",
              title: "标题",
              props: {
                text: "个人信息调研",
                level: 1,
                isCenter: false,
              },
            },
            {
              fe_id: Random.id(),
              type: "questionInput",
              title: "输入框1",
              props: {
                title: "你的姓名",
                placeholder: "请输入...",
              },
            },
            {
              fe_id: Random.id(),
              type: "questionInput",
              title: "输入框2",
              props: {
                title: "你的电话",
                placeholder: "请输入...",
              },
            },
          ],
        },
      };
    },
  },
  {
    url: "/api/question",
    method: "post",
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id(),
        },
      };
    },
  },
  {
    url: "/api/question",
    method: "get",
    response(ctx) {
      const { url = "", query = {} } = ctx;

      const isStar = url.indexOf("isStar=true");
      const isDeleted = url.indexOf("isDeleted=true");
      const pageSize = parseInt(query.pageSize) || 10;
      return {
        errno: 0,
        data: {
          list: getQuestionList({ isStar, isDeleted, len: pageSize }),
          total: 100,
        },
      };
    },
  },
  {
    url: "/api/question/:id",
    method: "patch",
    response() {
      return {
        errno: 0,
      };
    },
  },
  {
    url: "/api/question/duplicate/:id",
    method: "post",
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id,
        },
      };
    },
  },
  {
    url: "/api/question",
    method: "delete",
    response() {
      return {
        errno: 0,
      };
    },
  },
];
